package models

// import "github.com/gin-gonic/gin"

type Fexam struct {
	Eno       string  `gorm:"column:eno"`
	Fpolitial string  `gorm:"column:fpolitial"`
	Flanguage string  `gorm:"column:flanguage"`
	Fmajor1   string  `gorm:"column:fmajor1"`
	Fmajor2   string  `gorm:"column:fmajor2"`
	Fscore    string  `gorm:"column:fscore"`
}


func GetAllFexam(fexamParam map[string]interface{}) (error, []Fexam, int64) {
	var fexamData []Fexam
	page := fexamParam["page"].(int)
	pageSize := fexamParam["limit"].(int)
	searchText := fexamParam["searchText"].(string)
	var total int64
	err := db.Table("fexam").Where("eno like ?", "%"+searchText+"%").Order("fscore DESC").Count(&total).Find(&fexamData).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, fexamData, total
}

func AddFexam(fexamdata Fexam) (error, Fexam) {
	err := db.Table("fexam").Select("eno", "fpolitial", "flanguage", "fmajor1", "fmajor2","fscore").Create(&fexamdata).Error
	return err, fexamdata
}

func UpdateFexam(eno string, fexamdata Fexam) (error, Fexam) {
	err := db.Table("fexam").Where("eno = ?", fexamdata.Eno).Updates(&fexamdata).Error
	return err, fexamdata
}

func DeleteFexam(eno string) (error, Fexam) {
	var fexamdata Fexam
	fexamdata.Eno = eno
	err := db.Table("fexam").Where("eno = ?", eno).Find(&fexamdata).Delete(Fexam{}).Error
	return err, fexamdata
}
